<template>
	<view>
		<view class="listBot">
			<u-sticky bgColor="#fff">
				<u-tabs :list="list" :lineWidth="80" lineColor="#0F53AC" :activeStyle="activeStyle" :scrollable="false"
					:inactiveStyle="inactiveStyle" :itemStyle="itemStyle" @click="tabsClick" :current="current">
				</u-tabs>
			</u-sticky>
		</view>
		<view class="tab-page">
			<view class="list-wrapper" v-for="item in trobleList" :key="item.id" @click="handleTo(item)">
				<view class="top">
					<view class="left-title">{{item.planName}}</view>
					<view v-if="item.dangerNum" class="title-num">
						{{item.dangerNum}}
					</view>
					<view class="right-list" style="display: flex;">
						<view :style="{color:current == 0?'#8C8C8C':'#0F53AC'}">{{current == 0?'未巡查':'已巡查'}}</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="middle">巡查时间:{{item.planDate + (item.checkWay == 1?'-' + item.limitDate:'')}}</view>
				<view class="bottom">
					<view v-if="item.regionName" class="tags">{{item.regionName}}</view>
					<view class="tags">{{item.periodUnit}}</view>
				</view>
			</view>
			<u-loadmore v-if="total>7" :status="status" :line="true" />
		</view>
		<view class="empty-data" v-if="trobleList.length==0">
			<u-empty mode="data" :marginTop="100"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				activeStyle: {
					color: '#0F53AC',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				},
				inactiveStyle: {
					color: '#8c8c8c',
					transform: 'scale(1)'
				},
				itemStyle: {
					paddingLeft: '30rpx',
					paddingRight: '30rpx',
					paddingTop: '24rpx',
					paddingBottom: '24rpx',
					height: '48rpx'
				},
				current: 0,
				list: [{
					name: '未巡查',
				}, {
					name: '已巡查',
				}],
				params: {
					pn: 1,
					ps: 7,
					inspectionStatus: 0, //必须 0.未巡查   1.已巡查
				},
				trobleList: [],
				pages: 1,
				total: 0,
			}
		},

		onShow() {
			this.params.pn = 1;
			this.trobleList = []
			this.getList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.params.pn = 1;
			this.trobleList = []
			this.getList()
		},
		methods: {
			tabsClick(e) {
				this.current = e.index
				this.params.pn = 1;
				this.trobleList = []
				this.params.inspectionStatus = e.index;
				this.getList()
			},
			getList() {
				uni.$u.http.post(`/check/mobile/appInspectionRecord/inspectionRecordList`, this.params).then(res => {
					if (res.code == 0) {
						this.trobleList = this.trobleList.concat(res.data.records)
						this.pages = res.data.pages;
						this.total = res.data.total;
						uni.stopPullDownRefresh()
					}
				}).catch(err => {})
			},
			handleTo(item) {
				if (item.inspectionStatus) {
					// 已巡查
					uni.navigateTo({
						url: `/pages/subPackagesA/troble/notTroble?inspectionId=${item.id}&planName=${item.planName}&isInspec=${1}`
					})
				} else {
					// 未巡查
					uni.navigateTo({
						url: `/pages/subPackagesA/troble/notTroble?inspectionId=${item.id}&planName=${item.planName}&isInspec=${0}`
					})
				}
				// 逾期任务
				// uni.navigateTo({
				// 	url: '/pages/subPackagesA/troble/exceedTroble'
				// })
			}
		},
		onReachBottom() {
			if (this.params.pn >= this.pages) return;
			this.status = 'loading';
			this.params.pn = ++this.params.pn;
			setTimeout(() => {
				this.getList()
				if (this.params.pn >= this.pages) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		}
	}
</script>

<style lang="scss">
	page {
		background: #ffffff;
	}

	// .tab-page {
	// 	margin-top: 12rpx;
	// }

	.list-wrapper {
		background-color: #fff;
		padding: 40rpx 32rpx;
		position: relative;
		border-bottom: 1px solid #EDEDED;

		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left-title {
				width: 70%;
				font-size: 17px;
				font-weight: 500;
				color: #2B2B2B;
				text-align: left;
				word-wrap: break-word;
				word-break: break-all;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;

			}

			.title-num {
				width: 18px;
				height: 18px;
				border-radius: 100%;
				background: #FA5151;
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 24rpx;
				margin-left: 16rpx;
			}

			.right-status {
				width: 120rpx;
				height: 44rpx;
				opacity: 1;
				border-radius: 8rpx;
				background: rgba(255, 77, 77, 0.2);
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 24rpx;
				font-weight: 400;
				color: #FF4D4D;
			}

			.tags {
				color: #0F53AC;
				padding: 4px 12px;
				border: 2rpx solid #0F53AC;
				border-radius: 4px;
				font-size: 28rpx;
				line-height: 42rpx;
				margin-right: 6rpx;
				max-width: 50%;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}

		.middle {
			margin: 16rpx 0 12rpx;
			font-size: 16px;
			font-weight: 400;
			line-height: 20.27px;
			color: rgba(102, 102, 102, 1);
		}

		.bottom {
			margin-top: 24rpx;
			display: flex;
			// justify-content: space-between;
			align-items: center;

			// .left-box {
			// 	display: flex;

			// 	// width: 50%;
			// }

			.tags {
				margin-right: 20rpx;
				color: #0F53AC;
				padding: 8rpx 24rpx;
				border: 2rpx solid #0F53AC;
				border-radius: 8rpx;
				font-size: 24rpx;
				margin-right: 6rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				// background: #2173DE33;
			}

			.right-list {
				display: flex;
				align-items: center;
				font-size: 14px;
				font-weight: 400;
			}
		}

	}
</style>